import Vue from 'vue'
import Router from 'vue-router'

import Layout from '@/layout'

Vue.use(Router)

/**
 * 公共路由
 */
export const constantRoutes = [
    {
        path: '/login',
        component: ()=> import('@/views/login'),
        hidden: true
    },
    {
      path: '/register',
      component: () => import('@/views/register'),
      hidden: true
    },
    {
        path: '',
        component: Layout,
        redirect: 'index',
        children: [
            {
                path: 'index',
                name: 'Index',
                component: () => import('@/views/home/index'),
                meta: { title: '首页', icon: 'dashboard', affix: true }
            }
        ]
    },
    {
        path: '/blog',
        component: Layout,
        hidden: true,
        children: [
            {
                path: 'add/:blogId(\\d+)',
                component: () => import('@/views/article/blog/add'),
                name: 'BlogEdit',
                meta: { title: '编辑博客', icon: '' }
            }
        ]
    },
    {
        path: '/dict',
        component: Layout,
        hidden: true,
        children: [
            {
                path: 'type/data/:id(\\d+)',
                component: () => import('@/views/system/dict/data'),
                name: 'Data',
                meta: { title: '字典数据', icon: '' }
            }
        ]
    },
    {
        path: '/user',
        component: Layout,
        hidden: true,
        redirect: 'noredirect',
        children: [
            {
                path: 'profile',
                component: () => import('@/views/system/user/profile/index'),
                name: 'Profile',
                meta: { title: '个人中心', icon: 'user' }
            }
        ]
    },
    {
        path: '/404',
        name: 'Page404',
        component: () => import('@/views/404'),
        hidden: true
    }
]

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
    {
        path: '/dict',
        component: Layout,
        hidden: true,
        children: [
            {
                path: 'index/:dictId(\\d+)',
                component: () => import('@/views/system/dict/data'),
                name: 'Data',
                meta: { title: '字典数据', activeMenu: '/system/dict' }
            }
        ]
    }
]

export default new Router({
    mode: 'history', // 去掉url中的#
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
})

